package com.valveinspectionsys.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class DateUtil {

    /**
     * 获取当前日期时间
     * 
     * @return
     */
    public static String getDateTime() {
	Date dt = new Date();
	long tm = dt.getTime();
	return ((new java.sql.Date(tm)) + " " + (new java.sql.Time(tm)));
    }

    /**
     * 获取日期
     * 
     * @return
     */
    public static String getDate() {
	Date dt = new Date();
	long tm = dt.getTime();
	return (new java.sql.Date(tm)).toString();
    }

    /**
     * 得到当前日期前几天的日期
     * 
     * @return yyyy-mm-dd
     */
    public static String getBeforeDay(int num) {
	Calendar calendar = Calendar.getInstance();
	calendar.setTime(new Date());
	calendar.add(Calendar.DATE, -num);
	SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss", Locale.ENGLISH);
	return simpledateformat.format(calendar.getTime());
    }

    /**
     * 得到给定日期后几日的日期
     * 
     * @param num
     * @return
     */
    public static String getAfterDay(String date, int num) {
	SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd");
	Date a = null;
	try {
	    a = parser.parse(date);
	} catch (ParseException e) {
	    e.printStackTrace();
	}

	Calendar calendar = Calendar.getInstance();
	calendar.setTime(a);
	calendar.add(Calendar.DATE, num);
	SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
	return simpledateformat.format(calendar.getTime());
    }

    /**
     * 根据字符串得到日期型的日期
     * 
     * @param day
     * @return date
     */
    public static Date getStringToDate(String day) {
	SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd");
	Date a = new Date();
	try {
	    a = parser.parse(day);
	} catch (ParseException e) {
	    e.printStackTrace();
	}
	return a;
    }

    /**
     * 
     * @Title: getSqlDate
     * @Description: 根据字符串得到SQL日期
     * @param @param date 字符串日期
     * @param @return
     * @return java.sql.Date
     * @throws
     */
    public static java.sql.Date getSqlDate(String date) {

	return new java.sql.Date(getStringToDate(date).getTime());
    }

    /**
     * 
     * @Title: getSqlTimestamp
     * @Description: 获取时间的毫秒值
     * @param @return
     * @return java.sql.Timestamp
     * @throws
     */
    public static java.sql.Timestamp getSqlTimestamp() {
	return new java.sql.Timestamp(new java.util.Date().getTime());
    }

    /**
     * 
     * @Title: getsqlDate
     * @Description: 获取当前系统SQL时间
     * @param @return
     * @return java.sql.Date
     * @throws
     */
    public static java.sql.Date getsqlDate() {
	return new java.sql.Date(new java.util.Date().getTime());
    }

    public static Date getDate(String date) {
	java.text.DateFormat format = new SimpleDateFormat("yyyy-MM-dd:hh-mm");
	Date dates = null;
	try {
	    dates = format.parse(date);
	} catch (ParseException e) {

	    e.printStackTrace();
	}
	return dates;

    }

    public static String getMuntion(long time) {
	String str = "";
	int h = (int) (time / 1000 / 60 / 60);
	int m = (int) (time % 3600000 / 60000);
	int s = (int) (time % 60000 / 1000);
	str = h + "小时" + m + "分" + s + "秒";
	return str;
    }

    /**
     * 得到当前时间
     * 
     * @return
     */
    public static String getNowDate() {
	Calendar calendar = Calendar.getInstance();
	calendar.setTime(new Date());
	calendar.add(Calendar.DATE, -0);
	SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ", Locale.ENGLISH);
	return simpledateformat.format(calendar.getTime());
    }
    
    /**
     * 得到当前简写时间
     * @return
     */
    public static String getSimpleDate(){
	Calendar calendar = Calendar.getInstance();
	calendar.setTime(new Date());
	calendar.add(Calendar.DATE, -0);
	SimpleDateFormat simpledateformat = new SimpleDateFormat("yyMMdd ", Locale.ENGLISH);
	return simpledateformat.format(calendar.getTime());
    }
    
    /**
     * 得到当前月份
     * @return
     */
    public static String getMonthDate(){
	Calendar calendar = Calendar.getInstance();
	calendar.setTime(new Date());
	calendar.add(Calendar.DATE, -0);
	SimpleDateFormat simpledateformat = new SimpleDateFormat("MM月 ", Locale.ENGLISH);
	return simpledateformat.format(calendar.getTime());
    }
}
